<ui:composition template="../template/template.xhtml" xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui">
	<ui:define name="localizacao">
	<h:outputText value="&#160;" />
		<a href="listarConcursos.xhtml"> Concursos</a>
		<h:outputText value="&#160;>&#160;" />
		<a href="detalhesConcurso.xhtml">#{concursoMB.concursoSelecionado.nome}</a>
		<h:outputText value="&#160;>&#160;" />
		Disciplina: #{cadastrarDisciplinaMB.disciplinaSelecionada.nome}
		<h:outputText value="&#160;>&#160;" />
	</ui:define>
	<ui:define name="content">
		<h4>
			<b><h:outputText value="Concurso: " /></b>
			<h:outputText value="#{cadastrarDisciplinaMB.disciplinaSelecionada.concurso.nome}" />
		</h4>
		<h4>
			<b><h:outputText value="Disciplina: " /></b>
			<h:outputText value="#{cadastrarDisciplinaMB.disciplinaSelecionada.nome}" />
		</h4>
		<br />
		<h4>
			<h:outputText value="Conteudo Programatico: " />
		</h4>
		<br />
		<br />

		<p:panel>
			<p:growl id="growl" showDetail="true" sticky="false" life="4000" />
			<b><h:outputText value="Inserir Novo: " /></b>
			<br />
			<br />
			<h:form id="cadastroConteudo">
				<table>
					<tr>
						<td><h:outputText value="Nome: " /></td>
						<td><p:inputText id="nome" value="#{inserirConteudoMB.conteudo.nome}" required="true"
								requiredMessage="Campo Obrigatório" /></td>
						<td><p:message for="nome" /></td>
					</tr>
					<tr>
						<td><h:outputText value="Observacao: " /></td>
						<td><p:inputTextarea id="obs" value="#{inserirConteudoMB.conteudo.observacao}" /></td>
					</tr>
					<tr>
						<td><br /></td>
					</tr>
					<tr>
						<td><p:commandButton listener="#{cadastroConteudo}" process="@form" value="Salvar"
								oncomplete="if (!args.validationFailed) $('#cadastroConteudo\\:link_cadConteudo').click()"
								update=":form_lista_conteudos, cadastroConteudo" styleClass="ui-priority-primary"/></td>
						<p:commandLink style="display:none" id="link_cadConteudo"
							actionListener="#{inserirConteudoMB.cadastrarConteudo()}"
							update="cadastroConteudo, :growl, :form_lista_conteudos" />
					</tr>
				</table>
			</h:form>
		</p:panel>

		<h:form id="form_lista_conteudos">
       	 
		  <p:dataTable value="#{cadastrarDisciplinaMB.listaConteudos}" var="conteudo" id="lista_conteudos"
				emptyMessage="Nenhum conteudo cadastrado" paginator="true" rows="10" 
				paginatorTemplate="{PageLinks} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,15" editable="true"
				draggableColumns="true" paginatorAlwaysVisible="false" paginatorPosition="bottom">
				
				<p:ajax event="rowEdit" listener="#{inserirConteudoMB.onEdit}" update=":growl"/>
				<f:facet name="header">  
            		Conteudos Cadastrados
        		</f:facet>  
				 
				<p:column headerText="Conteudo">
					<p:cellEditor>  
		                <f:facet name="output">
							<h:outputText value="#{conteudo.nome}" />
						</f:facet>
						 <f:facet name="input">  
		                    <p:inputText value="#{conteudo.nome}" style="width:100%;"/>  
		                </f:facet>
					</p:cellEditor>
				</p:column>
				
				<p:column headerText="Observação">
					<p:cellEditor>  
		                <f:facet name="output">
							<h:outputText value="#{conteudo.observacao}" />
						</f:facet>
						<f:facet name="input">  
		                    <p:inputText value="#{conteudo.observacao}" style="width:100%"/>  
		                </f:facet>
					</p:cellEditor>
				</p:column>
				
				<p:column style="width:3%">
					<f:facet name="header">Editar</f:facet>
					<p:rowEditor />
				</p:column>
				
				<p:column headerText="Estudado">
					<p:selectBooleanCheckbox value="#{conteudo.estudado}">
						<p:ajax oncomplete="confirmation2.show()" update=":formEstudado"
							listener="#{inserirConteudoMB.selecionarConteudo(conteudo)}" />
					</p:selectBooleanCheckbox>
				</p:column>
				
				<p:column>
					<f:facet name="header">Acoes</f:facet>
					<p:commandButton id="excluir" icon="ui-icon-trash" title="Excluir"
						actionListener="#{inserirConteudoMB.selecionarConteudo(conteudo)}"
						oncomplete="confirmation.show()" update=":formRemover" />
				</p:column>
			</p:dataTable>
		</h:form>

		<h:form id="formEstudado">
			<p:confirmDialog id="confirmDialog2"
				message="Conteudo: #{inserirConteudoMB.conteudoSelecionado.nome}" header="Certeza? (mudar msg)"
				severity="alert" widgetVar="confirmation2">
				<p:commandButton id="confirm" value="Sim" oncomplete="confirmation2.hide()"
					action="#{inserirConteudoMB.cadastrarConteudo()}" />
				<p:commandButton id="decline" value="Nao" onclick="confirmation2.hide()" type="button" />
			</p:confirmDialog>
		</h:form>
		<h:form id="formRemover">
			<p:confirmDialog id="confirmDialog"
				message="Excluir o conteudo: #{inserirConteudoMB.conteudoSelecionado.nome}" header="Certeza?"
				severity="alert" widgetVar="confirmation">
				<p:commandButton id="confirm" value="Sim" oncomplete="confirmation.hide()"
					action="#{inserirConteudoMB.excluirConteudo()}" />
				<p:commandButton id="decline" value="Nao" onclick="confirmation.hide()" type="button" />
			</p:confirmDialog>
		</h:form>

		<h:form>
			<p:commandButton actionListener="#{concursoMB.urlDetalhesConcurso()}" value="Voltar"
			icon="ui-icon-circle-triangle-w" />
		</h:form>
	</ui:define>
</ui:composition>